## -*- coding: utf-8 -*-

<%
	## Import a database hook, as well as information from the operating system to determine if we can
	## display upload request information or database information.
	import os
	from db_backend import DatabaseInterface
	db = DatabaseInterface()
%>

<!DOCTYPE HTML>
<html>
	<head>
		## title and content are variables that are passed through to this template.
		<title>K'atun :: ${title}</title>
		<link rel="stylesheet" type='text/css' href='http://fonts.googleapis.com/css?family=Amaranth:400italic'>
		<link rel="stylesheet" type="text/css" href="templates/katun.css" />
	</head>	

	<body>
		<div id="container">
			<div id="banner">
				<h1><i>K'atun</i></h1>
			</div>
			
		<div id="sidebar">
			<h2>Library</h2>
			% if os.path.exists(db.db_path):
				<p>Run any valid SQL query on your collection here.</p>
			<div id="querybox"align="center">
				<form action = "query_db" enctype="multipart/form-data/" method = "post">
					<input type="text" name="query" size="25">
				</form>
			</div>
			<ul>
				<li><a href="music">Music</a></li>
				<li><a href="playlists">Playlists</a></li>
				<li><a href="favorites">Favorites</a></li>
				<li><a href="duplicates">Duplicates</a></li>
				<li><a href="get_help">Help</a></li>
			</ul>
			<br />
			<h2>Statistics</h2>
			<%
				## Extract statistics from the database.
				size = db.execute_query("select count(distinct title) from song;")[0][0]
				dups = db.execute_query("select count(*) from duplicates;")[0][0]
				genre = db.execute_query("select count(distinct genre) from song;")[0][0]
				
			%>
				<ul>
					<li>Music Collection Size: <b>${size}</b></li>
					<li>Duplicates in Collection: <b>${dups}</b></li>
					<li>Genres in Collection: <b>${genre}</b></li>
				</ul>
		% else:
			<form action="load_music" enctype="multipart/form-data/" method="post">
			<p>Where's your music?<br />
				<input type="text" name="location" size="15" />
			</p>
			<div>
				<input type="submit" value="Send" />
			</div>
			</form>
		%endif
		</div>

		<div id="content">
			${content}
		</div>
			

		<div id="footer">
			<p>Powered by <a href="http://www.cherrypy.org">CherryPy</a></p>
		</div>
	</body>
</html>
